<template>
  <el-container>
    <!--头部-->
    <el-header height="60px">
      <el-row class="header_div">
        <el-col :span="1">
          <div class="h_pic">
            <img src="../assets/icon/logo.png"/>
          </div>
        </el-col>
        <el-col :span="3">
          <div class="h_logo">
            云视车联
          </div>
        </el-col>
        <el-col :span="6" :offset="1"><div class="h_title">云视车联官网后台管理系统</div></el-col>
        <el-col :span="1" :offset="11"><div class="h_admin"><i class="el-icon-s-custom"></i></div></el-col>
        <el-col :span="1"><el-button @click="logout" type="primary" size="mini" class="h_button">注销</el-button></el-col>
      </el-row>
    </el-header>
    <el-container>
      <!--侧边-->
      <el-aside width="200px">
        <el-menu 
          background-color="#333333"
          router
          unique-opened
          :default-active="activityPath"
          active-text-color="#67C23A"
          text-color="#ccc"
          >
          <!--用户管理-->
          <el-menu-item index="/userManage" @click="saveNavState('/userManage')">
            <template slot="title">
              <i class="el-icon-user-solid"></i>
              <span>用户管理</span>
            </template>
          </el-menu-item>
          <!--产品管理-->
          <el-menu-item index="/productManage" @click="saveNavState('/productManage')">
            <template slot="title">
              <i class="el-icon-menu"></i>
              <span>产品管理</span>
            </template>
          </el-menu-item>
          <!--图片管理-->
          <el-submenu index="pictureManage">
            <template slot="title">
              <i class="el-icon-picture"></i>
              <span>图片管理</span>
            </template>
            <el-menu-item-group>
              <el-menu-item index="/rotationMap" @click="saveNavState('/rotationMap')"><span>轮播图</span></el-menu-item>
              <el-menu-item index="/bannerPicture" @click="saveNavState('//bannerPicture')"><span>横幅图片</span></el-menu-item>
            </el-menu-item-group>
          </el-submenu>
          <!--文章管理-->
          <el-submenu index="articleManage">
            <template slot="title">
              <i class="el-icon-s-order"></i>
              <span>文章管理</span>
            </template>
            <el-menu-item-group>
              <el-menu-item index="/articleContent" @click="saveNavState('/articleContent')"><span>文章内容</span></el-menu-item>
              <el-menu-item index="/articleType" @click="saveNavState('/articleType')"><span>文章类型</span></el-menu-item>
            </el-menu-item-group>
          </el-submenu>
        </el-menu>
      </el-aside>
      <!--主页-->
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  created(){
    //路径保存，用户在点击二级菜单时，将存放到session中，每次刷新时调用created方法，则取出session中的值
    var path=window.sessionStorage.getItem("activityPath")
    if(path!=null){
        this.activityPath=path
    }
  },
  data(){
    return{
      activityPath:'/userManage' //默认选择用户管理
    }
  },
  methods:{
    //路径保存
    saveNavState(activityPath){
      window.sessionStorage.setItem("activityPath",activityPath) //存放在session中
      this.activityPath=activityPath
    },
    //退出
    logout(){
      //清除Session
      window.sessionStorage.clear()
      //回到登录界面
      this.$router.push("/login")
    }
  }
}
</script>

<style lang="less" scoped>
  .el-container{
    height:100%;
  }
  /*header*/
  .el-header{
    padding-left:0%;
    background-color:#282828;
    border-bottom:solid 1px #888;
  }
  .header_div{
    line-height:60px;
    display:flex;
    box-sizing:border-box;
    .h_pic{
      img{
        margin:10px 10px;
        width:55px;
        height:40px;
        border-radius:4px;
        box-shadow: -3px 3px 3px rgb(137, 137, 241);
      }
    }
    .h_logo{
      padding-left:20px;
      color:white;
      font-size:25px;
      font-family:'楷体';
    }
    .h_title{
      color:rgba(255,255,255,0.8);
      font-size:22px;
      text-shadow: 1px 1px 2px #ccc;
    }
    .h_admin{
      padding-left:10px;
      color:white;
      font-size:35px;
      line-height:60px;
      cursor:pointer;
    }
  }
  /*main*/
  .el-main{
    background-color:#ccc;
  }
  /*aside*/
  .el-aside{
    background-color:#333333;
  }
  /*菜单*/
  .el-menu{
    border-right:none;
    user-select:none;
    padding-top:50px;
    span{
      font-weight:600;
      font-family:'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
    }
  }
</style>